package edu.tgc.web.controller.student;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;

import org.abyss.common.web.controller.easyui.CommonCrudEasyUiController;
import org.abyss.data.specifications.Rule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import edu.tgc.entity.student.TbClass;
import edu.tgc.entity.system.SysDept;
import edu.tgc.entity.system.SysUser;
import edu.tgc.service.student.TbClassService;
import edu.tgc.web.form.student.ClassForm;

@Controller
@RequestMapping(value="/student/class")
public class TbClassController extends CommonCrudEasyUiController<TbClass, UUID, ClassForm> {
	@Autowired
	private TbClassService service;
	@Override
	public Specification<TbClass> buildSearch(ClassForm form) {
		HashSet<Rule> rules=new HashSet<>();
		String name=form.getName();
		if(StringUtils.hasText(name)){
			rules.add(Rule.property("name").contain(name));
		}
		SysDept dept = form.getParentdept();
		if(dept!=null){
			rules.add(Rule.property("parentDept.id").equal(dept.getId()));
		}
		Integer year=form.getYear();
		if(year!=null){
			rules.add(Rule.property("year").equal(year));
		}
		SysUser manager = form.getManager();
		if(manager!=null){
			rules.add(Rule.property("manager.id").equal(manager.getId()));
		}
		Boolean isUsed = form.getIsUsed();
		if(isUsed!=null){
			rules.add(Rule.property("isUsed").equal(isUsed));
		}
		return Rule.and(rules).toSpecification();
	}
	
	@RequestMapping(value="/banjiCombo")
	@ResponseBody
	public Object banjiCombo(){
		List<HashMap<String, Object>> result=service.banjiCombo();
		return result;
	}

}
